<?php

	/**
	 * Lyrics Item
	 *
	 * @author anton.perkin
	 * @version 1.0
	 *
	 */
	class LyricsItem
	{
		/* VARIABLES */
		
		public $id;
		public $name;
		public $displayName;
		public $vintage;
		public $region;
		public $subRegion;
		public $grape;
		public $varietal;
		public $appelation;
		public $producer;
		public $webAddress;
		public $type;
		public $photoURL;
		public $source;
		public $urlId;
		
		
		/* METHODS */
		
		/**
		 * Saves LyricsItem into database
		 *
		 */
		public function Save()
		{
			if (DB::ExecuteSQL("
				INSERT INTO t_lyrics
				(
					lyrics_id,
					name,
					display_name,
					vintage,
					region,
					sub_region,
					grape,
					varietal,
					appelation,
					producer,
					web_address,
					type,
					photo_url,
					source,
					url_id
				)
				VALUES
				(
					$this->id,
					'".addslashes($this->name)."',
					'".addslashes($this->displayName)."',
					$this->vintage,
					'".addslashes($this->region)."',
					'".addslashes($this->subRegion)."',
					'".addslashes($this->grape)."',
					'".addslashes($this->varietal)."',
					'".addslashes($this->appelation)."',
					'".addslashes($this->producer)."',
					'$this->webAddress',
					'".addslashes($this->type)."',
					'$this->photoURL',
					'$this->source',
					$this->urlId
				);
			") === true)
			{
				$this->Log(true);
				$result = true;
			}	
			else 
			{
				$this->Log(false);
				$result = false;
			}	

			return $result;
		}
		
		/**
		 * Saves lyrics URL into database
		 *
		 * @param string $url url
		 * @param string $source source
		 * 
		 * @return boolean
		 * 
		 */
		public function SaveURL($url, $source)
		{
			if (DB::ExecuteSQL("
				INSERT INTO t_lyrics_urls
				(
					url,
					source
				)
				VALUES
				(
					'$url',
					'$source'
				);
					
			") === true)
			{
				$this->LogURL($url, $source, true);
				$result = true;
			}	
			else 
			{
				$this->LogURL($url, $source, false);
				$result = false;
			}	

			return $result;
		}
		
		/**
		 * Creates log entry for the inserted lyrics
		 * 
		 * @param boolean $success result
		 *
		 */
		private function Log($success)
		{
			$color = ($success) ? 'green' : 'red';
			
			echo "<span style = 'color: $color; '>
			----------------------------------------------------------------------------------------------------------------<br />
			Id: $this->id | Name: $this->name | DisplayName: $this->displayName | Vintage: $this->vintage | Region: $this->region | 
			SubRegion: $this->subRegion | Grape: $this->grape | Varietal: $this->varietal | Appelation: $this->appelation | 
			Producer: $this->producer | WebAddress: $this->webAddress | Type: $this->type | PhotoURL: $this->photoURL <br />
			----------------------------------------------------------------------------------------------------------------</span><br />";
		}

		/**
		 * Creates log entry for the inserted lyrics URL
		 *
		 * @param string $url url
		 * @param string $source source
		 * @param boolean $success result
		 */
		private function LogURL($url, $source, $success)
		{
			$color = ($success) ? 'green' : 'red';
			
			echo "<span style = 'color: $color; '>
			URL: $url | Source: $source
			</span><br />";
		}
		
	}

?>